package Data_base;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Scanner;
//查询
public class Chaxun {
    public  void chaxun() throws Exception
    {
        try
        {
            DB ty=new DB();
            Class.forName(ty.Driver_class);
            Connection con= DriverManager.getConnection(ty.Database_url,ty.Database_user,ty.Database_password);
            Scanner sc=new Scanner(System.in);
            System.out.print("请输入要查询的id:");
            String zh=sc.nextLine();
            Statement fasong=con.createStatement();//将语句发送到数据库
            String sql="select * from users where id='"+zh+"'";
            ResultSet huoqu=fasong.executeQuery(sql); //获取执行sql语句返回的结果
            while(huoqu.next()) {
                System.out.println(huoqu.getString(1)+" "+
                        huoqu.getString(2)+" "+
                        huoqu.getString(3)+"  " +
                        huoqu.getString(4) + "  "+
                        huoqu.getString(5));
            }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
